<template>
  <el-dialog :title="title" style="top: -40px" :visible.sync="open" @close="cancel" width="90%" append-to-body>
    <div style="height: 650px;overflow: auto">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" size="mini">
        <el-row>
          <el-col :span="6">
            <el-form-item label="报价单号" prop="bjdh">
              <el-input v-model="form.bjdh" @input="verifyBjdh" placeholder="请输入报价单号" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="完工编号" prop="wgdh">
              <el-input
                v-model="form.wgdh"
                placeholder="请输入完工编号"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="合同金额" prop="htje">
              <el-input v-model="form.htje" :min="0" type="number" placeholder="请输入合同金额" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报价日期" prop="bjrq">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.bjrq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择报价日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="客户名称" prop="khname">
              <el-input v-model="form.khname" placeholder="请选择客户">
                <el-button style="background-color: #92C3FE;color: black" type="warning" slot="prepend" @click.native="selectUser"> 选择客户 </el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户地址" prop="khdz">
              <el-input
                v-model="form.khdz"
                placeholder="请输入客户地址" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户税号" prop="khsh">
              <el-input
                v-model="form.khsh"
                placeholder="请输入客户税号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="报价单附件" prop="bjdfj">
              <el-upload
                ref="bjdUpload"
                class="upload-demo"
                :action="src"
                :on-success="handleSuccessYwd"
                :on-error="handleError"
                :before-remove="handleRemoveYwd"
                :headers="uploadHeaders"
                accept=".xlsx, .xls"
                multiple
                :limit="1"
                :file-list="bjdFjList"
                :on-exceed="handleExceed"
                :on-preview="handlePreview"
              >
                <el-button size="small" type="primary"> <i class="el-icon-upload"></i> 点击报价单上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="完工单附件" prop="wgdfj">
              <el-upload
                ref="wgdUpload"
                class="upload-demo"
                :action="src"
                :on-success="handleSuccessWgd"
                :on-error="handleError"
                :before-remove="handleRemoveWgd"
                :headers="uploadHeaders"
                accept=".xlsx, .xls"
                multiple
                :limit="1"
                :file-list="wgdFjList"
                :on-exceed="handleExceed"
                :on-preview="handlePreview"
              >
                <el-button size="small" type="warning"> <i class="el-icon-upload"></i> 点击完工单上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="检测方式" prop="jcfs">
              <el-radio-group v-model="form.jcfs">
                <el-radio :label="'1'" border>下场</el-radio>
                <el-radio :label="'2'" border>送检</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="下场/送检日期" prop="xcrq">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.xcrq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择下场日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下场状态" prop="xczt">
              <el-radio-group v-model="form.xczt">
                <el-radio v-for="item in xcList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="下场负责人">
              <el-input v-model="form.xcfzrname" readonly placeholder="请选择下场负责人">
                <el-button style="background-color: #92C3FE;color: black" type="primary" slot="prepend" @click.native="selectXcry"> 选择下场负责人 </el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下场人员">
              <el-input v-model="form.xcryname" readonly placeholder="请选择下场人员">
                <el-button style="background-color: #92C3FE;color: black" type="primary" slot="prepend" @click.native="selectXcry"> 选择下场人员 </el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="完工日期" prop="wgrq">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.wgrq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择完工日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="证书份数" prop="zjfs">
              <el-input
                v-model="form.zjfs"
                type="number"
                :min="0"
                placeholder="请输入证书份数"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="到账账号" prop="dzzh">
              <el-select v-model="form.dzzh" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="item in dzzhList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="外包情况" prop="wbqk">
              <el-radio-group v-model="form.wbqk">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="是否已开发票" prop="sfkp">
              <el-radio-group v-model="form.sfkp">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开票金额(元)" prop="kpje">
              <el-input
                type="number"
                v-model="form.kpje"
                :min="0"
                placeholder="开票金额"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="发票号" prop="fph">
              <el-input
                v-model="form.fph"
                placeholder="发票号"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开票日期" prop="kprq">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.kprq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择开票日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="是否回款" prop="sfhk">
              <el-radio-group v-model="form.sfhk">
                <el-radio v-for="item in hkList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="回款金额" prop="hkje">
              <el-input type="number" :min="0" v-model="form.hkje" placeholder="请输入回款金额" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="回款日期" prop="hkrq">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.hkrq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择回款日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="bz">
              <el-input
                maxlength="1000"
                :autosize="{ minRows: 2, maxRows: 3 }"
                show-word-limit
                v-model="form.bz"
                type="textarea"
                placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="申请电子档" prop="sfsqdzd">
              <el-radio-group v-model="form.sfsqdzd">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="电子档是否给客户" prop="sfgkhdzd" label-width="140px">
              <el-radio-group v-model="form.sfgkhdzd">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="纸质打印" prop="zzdy">
              <el-radio-group v-model="form.zzdy">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="已邮寄客户" prop="yyjkh">
              <el-radio-group v-model="form.yyjkh">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="下场通知用户" prop="xctzyh">
              <el-radio-group v-model="form.xctzyh">
                <el-radio v-for="item in sfList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="特殊处理" prop="tscl">
              <el-radio-group v-model="form.tscl">
                <el-radio v-for="item in tsclList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属公司" prop="ssgs">
              <el-radio-group v-model="form.ssgs">
                <el-radio v-for="item in ssgsList" :label="item.dictValue" border>{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="原始单" prop="ysfj">
              <el-upload
                ref="ysUpload"
                class="upload-demo"
                :action="src"
                :on-success="handleSuccessYsd"
                :before-remove="handleRemoveYsd"
                :headers="uploadHeaders"
                multiple
                :file-list="ysFjList"
                :on-preview="handlePreview"
              >
                <el-button size="small" type="success"> <i class="el-icon-upload"></i> 点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单客户盖章" prop="ddkhgzhc">
              <el-upload
                ref="khddUpload"
                class="upload-demo"
                name="files"
                :action="ddkhSrc"
                :on-success="handleSuccessKhdd"
                :before-remove="handleRemoveKhdd"
                :headers="uploadHeaders"
                :file-list="khddFjList"
                :on-preview="handlePreviewKhdd"
              >
                <el-button :disabled="tijiao" size="small" style="background-color: orange;color: white"> <i class="el-icon-upload"></i> 点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
    <!-- 客户列表 -->
    <khList v-if="showUser" :showUser="showUser" @selectData="selectData" @closeDialog="closeDialog"></khList>
    <!-- 选择下场人员 -->
    <xcForm
      v-if="showUserDialog"
      :showSelectUser="showUserDialog"
      :form="xcData"
      @close="closeUser"
      @xcryData="xcryData"
    ></xcForm>
    <!-- 预览组件 -->
    <PdfPreView
      v-if="showPdf"
      :showPdf="showPdf"
      :fjId="fjId"
      :title="fjTitle"
      @cancel="cancelPdf"
    ></PdfPreView>
  </el-dialog>
</template>

<script>
import { addYwdwgd, getYwdwgd, updateYwdwgd, verifyBh } from '@/api/gd/ywdwgd'
import khList from "@/views/gd/ywd/khList.vue";
import xcForm from '@/views/gd/xcap/ywdwgdXcForm.vue'
import PdfPreView from '@/views/components/componse/PdfView.vue'
import { allListFj, delFj, getFjById } from '@/api/gd/fj'
import { getToken } from '@/utils/auth'
export default {
  name: 'formInfor',
  components: { xcForm, khList, PdfPreView },
  props: {
    title: {
      type: String
    },
    formInfo: {
      type: Object
    },
    open: {
      type: Boolean
    },
    type: {
      type: Number
    }
  },
  data() {
    return {
      // 附件开始
      src: this.uploadSrc + '/gd/fj/file/upload',
      ddkhSrc: this.uploadSrc + '/gd/fj/file/batchUpload',
      uploadHeaders: { 'Authorization': 'Bearer ' + getToken() }, // 如果需要CSRF保护的话
      tijiao: false,
      bjdFjList: [],
      wgdFjList: [],
      ysFjList: [],
      khddFjList: [],
      // 附件结束
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bjdh: [
          { required: true, message: "报价单号不能为空", trigger: "blur" }
        ],
        khname: [
          { required: true, message: "客户名称不能为空", trigger: "blur" }
        ],
        htje: [
          { required: true, message: "合同金额不能为空", trigger: "blur" }
        ],
        xcrq: [
          { required: true, message: "请选择下场日期", trigger: "blur" }
        ]
      },
      // 按钮loading
      buttonLoading: false,
      showUser: false,
      showUserDialog: false,
      xcData: {},
      showPdf: false,
      fjId: "",
      fjTitle: "",
      sfList: [],
      xcList: [],
      hkList: [],
      sjztList: [],
      dzzhList: [],
      tsclList: [],
      ssgsList: [],
    }
  },
  async created() {
    // type 1 是新增模式，2 修改
    if (this.type === 1) {
      this.form = this.formInfo
    }else if (this.type === 2) {
      // 如果是修改模式的话，则通过当前的id查询一下详细信息
      await this.showInfo(this.formInfo)
    }
    this.getDict()
  },
  methods: {
    verifyBjdh(val) {
      verifyBh(val).then(res => {
        if (res.code === 200 && res.data) {
          this.$message.error("当前报价单号已存在！")
        }
      })
    },
    // --客户列表
    selectUser() {
      this.showUser = true
    },
    closeDialog() {
      this.showUser = false
    },
    xcryData(row) {
      this.form.xcfzr = row.xcfzr
      this.form.xcfzrname = row.xcfzrname
      this.form.xcry = row.xcry
      this.form.xcryname = row.xcryname
      this.form.xcrq = row.xcrq
      this.showUserDialog = false
    },
    selectData(row) {
      this.form.khid = row.id
      this.form.khname = row.khname
      this.form.khdz = row.dz
      this.form.khsh = row.sh
      this.closeDialog()
    },
    // --下场人员
    closeUser() {
      this.xcData = {}
      this.showUserDialog = false
      this.getList()
    },
    selectXcry() {
      this.xcData = this.form
      this.showUserDialog = true
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateYwdwgd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.cancel()
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addYwdwgd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.cancel()
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    cancel() {
      this.$emit("closeForm")
    },
    async showInfo(row) {
      await getYwdwgd(row.id).then(async res => {
        if (res.code === 200) {
          // 通过业务单附件，完工单附件，进行查询附件列表
          let bjdFjIds = []
          let wgdFjIds = []
          let ysFjIds = []
          let khhcFjIds = []
          if(res.data.bjdfj !== null && res.data.bjdfj !== "") bjdFjIds.push(res.data.bjdfj)
          if(res.data.bjdfjpdf !== null && res.data.bjdfjpdf !== "") bjdFjIds.push(res.data.bjdfjpdf)
          if(res.data.wgdfj !== null && res.data.wgdfj !== "") wgdFjIds.push(res.data.wgdfj)
          if(res.data.wgdfjpdf !== null && res.data.wgdfjpdf !== "") wgdFjIds.push(res.data.wgdfjpdf)
          if(res.data.ysfj !== null && res.data.ysfj !== "") ysFjIds.push(res.data.ysfj)
          if(res.data.ddkhgzhc !== null && res.data.ddkhgzhc !== "") khhcFjIds.push(res.data.ddkhgzhc)
          // 报价单附件不为空则查询
          if (bjdFjIds.length > 0) {
            allListFj(bjdFjIds.toString()).then(bjdResult => {
              let list = bjdResult
              if (list.length > 0 && list[0].fjtype.includes("pdf")) {
                list.reverse()
              }
              this.bjdFjList = []
              list.forEach(item => {
                this.bjdFjList.push(
                  {fjid: item.fjid, name: item.fjname,  path: item.fjpath}
                )
              })
            })
          }
          // 完工单附件不为空则查询
          if (wgdFjIds.length > 0) {
            allListFj(wgdFjIds.toString()).then(wgdResult => {
              let list = wgdResult
              if (list.length > 0 && list[0].fjtype.includes("pdf")) {
                list.reverse()
              }
              this.wgdFjList = []
              list.forEach(item => {
                this.wgdFjList.push(
                  {fjid: item.fjid, name: item.fjname,  path: item.fjpath}
                )
              })
            })
          }
          // 原始附件不为空则查询
          if (ysFjIds.length > 0) {
            allListFj(ysFjIds.toString()).then(ysResult => {
              let list = ysResult
              this.ysFjList = []
              list.forEach(item => {
                this.ysFjList.push(
                  {fjid: item.fjid, name: item.fjname,  path: item.fjpath}
                )
              })
            })
          }
          // 客户回传
          if (khhcFjIds.length > 0) {
            allListFj(khhcFjIds.toString()).then(ysResult => {
              let list = ysResult
              this.khddFjList = []
              list.forEach(item => {
                this.khddFjList.push(
                  {fjid: item.fjid, name: item.fjname,  path: item.fjpath}
                )
              })
            })
          }
          this.form = res.data
        }
      })
    },
    // ======  上传开始  ======
    handleSuccessKhdd(response, file, fileList) {
      // 更新状态或者通知用户上传成功
      if (response !== null && response !== undefined) {
        this.$message.success('上传成功');
        // 上传成功以后，将id设置
          this.khddFjList.push(
            {fjid: response[0].fj, name: response[0].fjname,  path: response[0].fjpath}
          )
        let fileIds = []
        this.khddFjList.forEach(item => {
          fileIds.push(item.fjid)
        })
        this.form.ddkhgzhc = fileIds.toString()
      }else {
        this.$message.success('上传失败');
      }


      //   this.khddFjList = []
      //   this.form.ddkhgzhc = response.fj
      //   this.khddFjList.push(
      //     {fjid: response.fj, name: response.fjname,  path: response.fjpath}
      //   )
      // }
    },
    handleSuccessYsd(response, file) {
      // 更新状态或者通知用户上传成功
      this.$message.success('上传成功');
      // 上传成功以后，将id设置
      this.ysFjList = []
      this.form.ysfj = response.fj
      this.ysFjList.push(
        {fjid: response.fj, name: response.fjname,  path: response.fjpath}
      )
    },
    handleSuccessYwd(response, file) {
      // 更新状态或者通知用户上传成功
      this.$message.success('上传成功');
      // 上传成功以后，将id设置
      this.bjdFjList = []
      this.form.bjdfj = response.fj
      this.form.bjdfjpdf = response.fjpdf
      this.bjdFjList.push(
        {fjid: response.fj, name: response.fjname,  path: response.fjpath},
        {fjid: response.fjpdf, name: response.fjpdfname,  path: response.fjpdfpath}
      )
    },
    handleSuccessWgd(response, file) {
      // 更新状态或者通知用户上传成功
      this.$message.success('上传成功');
      this.wgdFjList = []
      // 上传成功以后，将id设置
      this.form.wgdfj = response.fj
      this.form.wgdfjpdf = response.fjpdf
      this.wgdFjList.push(
        {fjid: response.fj, name: response.fjname,  path: response.fjpath},
        {fjid: response.fjpdf, name: response.fjpdfname,  path: response.fjpdfpath}
      )
    },
    // 上传失败回调
    handleError(err, file) {
      // 处理错误并通知用户
      this.$message.error('上传失败：', err);
      this.$refs.upload.clearFiles()
    },
    // 删除原始单回调
    handleRemoveKhdd(file, fileList) {
      // 判断当前的状态是否是预览状态，如果是预览状态，则不可以删除
      this.$modal.confirm('请确认是否删除附件名称为：'+file.name+' 的数据?').then(() => {
        // 调用删除附件功能，将附件进行删除
        let fjId = []
        fjId.push(file.id || file.fjid)
        this.buttonLoading = true;
        delFj(fjId).then(res => {
          if (res.code === 200) {
            // 删除后更新数据, 将删除的附件id删除掉
            let delIds = this.form.ddkhgzhc.split(",");
            let filteredArray = delIds.filter(item => item !== (file.id || file.fjid));
            this.form.ddkhgzhc = filteredArray.toString()
            let than = this
            updateYwdwgd(this.form).then(response => {
              this.$message.success("删除成功！")
              setTimeout(function() {
                than.buttonLoading = false;
              }, 2000)
            })
          }
        })
      }).catch(() => {
        fileList.push(file)
      })

    },
    // 删除原始单回调
    handleRemoveYsd(file, fileList) {
      // 判断当前的状态是否是预览状态，如果是预览状态，则不可以删除
      this.$modal.confirm('请确认是否删除附件名称为：'+file.name+' 的数据?').then(() => {
        // 调用删除附件功能，将附件进行删除
        let fjId = []
        fjId.push(file.id || file.fjid)
        fileList.forEach(item => {
          fjId.push(item.id || item.fjid)
        })
        this.buttonLoading = true;
        delFj(fjId).then(res => {
          if (res.code === 200) {
            this.$message.success("删除成功！")
            // 删除后更新数据
            this.form.ysfj = ''
            this.$refs.ysUpload.clearFiles()
            let than = this
            updateYwdwgd(this.form).then(response => {
              setTimeout(function() {
                than.buttonLoading = false;
              }, 2000)
            })
          }
        })
      }).catch(() => {
        fileList.push(file)
      })
    },
    // 删除回调
    handleRemoveYwd(file, fileList) {
      // 判断当前的状态是否是预览状态，如果是预览状态，则不可以删除
      this.$modal.confirm('请确认是否删除附件名称为：'+file.name+' 的数据?').then(() => {
        // 调用删除附件功能，将附件进行删除
        let fjId = []
        fjId.push(file.id || file.fjid)
        fileList.forEach(item => {
          fjId.push(item.id || item.fjid)
        })
        this.buttonLoading = true;
        delFj(fjId).then(res => {
          if (res.code === 200) {
            this.$message.success("删除成功！")
            // 删除后更新数据
            this.form.bjdfj = ''
            this.form.bjdfjpdf = ''
            this.$refs.bjdUpload.clearFiles()
            let than = this
            updateYwdwgd(this.form).then(response => {
              setTimeout(function() {
                than.buttonLoading = false;
              }, 2000)
            })
          }
        })
      }).catch(() => {
        fileList.push(file)
      })
    },
    handleRemoveWgd(file, fileList) {
      // 判断当前的状态是否是预览状态，如果是预览状态，则不可以删除
      this.$modal.confirm('请确认是否删除附件名称为：'+file.name+' 的数据?').then(() => {
        // 调用删除附件功能，将附件进行删除
        let fjId = []
        fjId.push(file.id || file.fjid)
        fileList.forEach(item => {
          fjId.push(item.id || item.fjid)
        })
        this.buttonLoading = true;
         delFj(fjId).then(res => {
          if (res.code === 200) {
            this.$message.success("删除成功！")
            // 删除后更新数据
            this.form.wgdfj = ''
            this.form.wgdfjpdf = ''
            this.$refs.wgdUpload.clearFiles()
            let than = this
            updateYwdwgd(this.form).then(response => {
              setTimeout(function() {
                than.buttonLoading = false;
              }, 2000)
            })
          }
        })
      }).catch(() => {
        fileList.push(file)
      })
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件`);
    },
    handlePreviewKhdd(file) {
      let id = file.fjid || file.response.fj
      getFjById(id, 'blob').then(response => {
        const binaryData = [];
        binaryData.push(response);
        let url = window.URL.createObjectURL(new Blob(binaryData, { type: 'application/octet-stream' }));
        const link = document.createElement('a');
        link.href = url
        link.download = file.name;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      })
    },
    // 文件点击回调
    handlePreview(file) {
      let suffix = file.name.substring(file.name.lastIndexOf(".") + 1);
      if (suffix === 'pdf') {
        this.showPdf = true
        this.fjId = file.fjid
        this.fjTitle = "PDF预览"
      }else {
        let id = file.fjid || file.response.fj
        getFjById(id, 'blob').then(response => {
          const binaryData = [];
          binaryData.push(response);
          let url = window.URL.createObjectURL(new Blob(binaryData, { type: 'application/octet-stream' }));
          const link = document.createElement('a');
          link.href = url
          link.download = file.name;
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
      }

    },
    cancelPdf() {
      this.showPdf = false
    },
    // ======  上传结束  ====
    getDict() {
      this.getDicts("gd_sf").then(res => {
        this.sfList = res.data
      })
      // 是否已下场
      this.getDicts("gd_xczt_xbb").then(res => {
        this.xcList = res.data
      })
      // 是否回款
      this.getDicts("gd_sfhk").then(res => {
        this.hkList = res.data
      })
      // 送检状态
      this.getDicts("gd_sjzt").then(res => {
        this.sjztList = res.data
      })
      // 到账账号
      this.getDicts("gd_dzzh").then(res => {
        this.dzzhList = res.data
      })
      // 特殊处理
      this.getDicts("gd_tscl").then(res => {
        this.tsclList = res.data
      })
      // 特殊处理
      this.getDicts("gd_ssgs").then(res => {
        this.ssgsList = res.data
      })
    },
  }
}
</script>

<style scoped>
.el-radio {
  margin-right: 0px;
}
.el-checkbox {
  margin-right: 0px;
}
</style>
